/**
 * 
 */
package org.threebitsoftware.tbb.module.simpletext;

import java.util.Vector;
import org.threebitsoftware.tbb.dao.*;

import junit.framework.TestCase;

/**
 * @author Erickson Cabinta
 *
 */
public class SimpleTextExporterTest extends TestCase {

	/**
	 * Test method for {@link org.threebitsoftware.tbb.module.simpletext.SimpleTextExporter#canExportMultipleContacts()}.
	 */
	public void testCanExportMultipleContacts() {
		SimpleTextExporter exportContactsToFile = new SimpleTextExporter();
		
		if (exportContactsToFile.canExportMultipleContacts()) {
			System.out.println("Can export multiple contacts");
		} else {
			System.out.println("Can not export multiple contacts");
		}
	}

	/**
	 * Test method for {@link org.threebitsoftware.tbb.module.simpletext.SimpleTextExporter#exportContactToFile(java.lang.String, org.threebitsoftware.tbb.dao.Contact)}.
	 */
	public void testExportContactToFileStringContact() {
		SimpleTextExporter exportContactsToFile = new SimpleTextExporter();
		String myStrFilePath = new String("C:\\Users\\ABBA\\My Documents\\Downloads\\contact.txt");
		
		try {
			initContact(false);
			
			if (exportContactsToFile.canExportMultipleContacts()) {
				
				if (!exportContactsToFile.exportContactToFile(myStrFilePath, myContact)) {
					fail("Contacts were not saved to file");
				}
			}
			
		} catch (Exception e) {
			fail("Exception found. Contacts were not saved to file");
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link org.threebitsoftware.tbb.module.simpletext.SimpleTextExporter#exportContactToFile(java.lang.String, org.threebitsoftware.tbb.dao.Contact[])}.
	 */
	public void testExportContactToFileStringContactArray() {
		SimpleTextExporter exportContactsToFile = new SimpleTextExporter();
		String myStrFilePath = new String("C:\\Users\\ABBA\\My Documents\\Downloads\\contacts.txt");
		
		try {
			initContact(true);
			
			if (exportContactsToFile.canExportMultipleContacts()) {
				
				if (!exportContactsToFile.exportContactToFile(myStrFilePath, myContacts)) {
					fail("Contacts were not saved to file");
				}
			}
			
		} catch (Exception e) {
			fail("Exception found. Contacts were not saved to file");
			e.printStackTrace();
		}
	}

	/**
	 * Test method for {@link org.threebitsoftware.tbb.module.simpletext.SimpleTextExporter#getGUI()}.
	 */
	public void testGetGUI() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link org.threebitsoftware.tbb.module.simpletext.SimpleTextExporter#getMergeClassName()}.
	 */
	public void testGetMergeClassName() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for {@link org.threebitsoftware.tbb.module.simpletext.SimpleTextExporter#iHaveMyOwnGUI()}.
	 */
	public void testIHaveMyOwnGUI() {
		fail("Not yet implemented");
	}

	private void initContact(boolean initializeArray) {
		
		// Initialize example1 with addresses, phone numbers and
		// emails
		if (!examplesHasBeenInitialized) {
			
			// Set up the user app id and contact ids
			example1.setIdAppUser(idUserApp);
			example2.setIdAppUser(idUserApp);
			example3.setIdAppUser(idUserApp);
			example4.setIdAppUser(idUserApp);
			
			example1.setIdContact(idContactEx1);
			example2.setIdContact(idContactEx2);
			example3.setIdContact(idContactEx3);
			example4.setIdContact(idContactEx4);
			
			// Set up the addresses for Example 1 and 4
			Vector <Address> addressesForExample1 =
				new Vector<Address>();
			Vector <Address> addressesForExample4 =
				new Vector<Address>();
			
			addressesForExample1.add(address1);
			addressesForExample1.add(address2);
			example1.setAddresses(addressesForExample1);
			
			addressesForExample4.add(address2);
			example4.setAddresses(addressesForExample4);
			
			// Set up the phone numbers for Example 1 and 4
			Vector<PhoneNumber> phoneNumbersForExample1 =
				new Vector<PhoneNumber>();
			Vector<PhoneNumber> phoneNumbersForExample4 =
				new Vector<PhoneNumber>();
			
			phoneNumbersForExample1.add(phoneNumber1);
			phoneNumbersForExample1.add(phoneNumber2);
			example1.setPhoneNumbers(phoneNumbersForExample1);
			
			phoneNumbersForExample4.add(phoneNumber2);
			example4.setPhoneNumbers(phoneNumbersForExample4);
			
			// Set up the e-mails for Example 1 and 4
			Vector <EmailAddress> emailsForExample1 =
				new Vector<EmailAddress>();
			Vector <EmailAddress> emailsForExample4 =
				new Vector<EmailAddress>();
			
			emailsForExample1.add(email1);
			emailsForExample1.add(email2);
			example1.setEmails(emailsForExample1);
			
			emailsForExample4.add(email2);
			example1.setEmails(emailsForExample4);
			
			examplesHasBeenInitialized = true;
		}
		
		// Initialize the array of contacts or just the one contacts
		if (initializeArray) {
			if (myContacts == null) {
				
				myContacts = new Contact[4];
				
				myContacts[0] = example1;
				myContacts[1] = example2;
				myContacts[2] = example3;
				myContacts[3] = example4;

			}
			
		} else {
			myContact = example1;
		}
	}
	
	private boolean examplesHasBeenInitialized = false;
	private int idUserApp = 12345;
	
	private int idContactEx1 = 1001;
	private int idAddress1Ex1 = 1;
	private int idAddress2Ex1 = 2;
	private int idPhoneNumber1Ex1 = 1;
	private int idPhoneNumber2Ex1 = 2;
	private int idEmail1Ex1 = 3;
	private int idEmail2Ex1 = 4;
	
	private int idContactEx2 = 2001;

	private int idContactEx3 = 5005;
	
	private int idContactEx4 = 3456;
	private int idAddress1Ex4 = 5;
	private int PhoneNumber1Ex4 = 6;
	private int idEmail1Ex4 = 7;

	private Contact []myContacts = null;
	private Contact myContact;
	
	private Contact example1 = 
		new Contact ("Billy", "Tang", "", "Jr.", "Dr.", "Johnson And Johnson, Inc", "Doctor", true);
	private Contact example2 =
		new Contact ("Paul", "Wagner", "Ice Weasel", "", "Mr.", "IBM, Inc.", "President", true);
	private Contact example3 =
		new Contact ("Parshu", "Loke", "Aloker", "", "", "Cisco Systems, Inc.", "Engineer", true);
	private Contact example4 =
		new Contact ("", "", "", "", "", "Three Bit Software", "", false);
	
	private PhoneNumber phoneNumber1 = new PhoneNumber("+1-123-123-1234", "Home");
	private PhoneNumber phoneNumber2 = new PhoneNumber("+1-234+234+2345", "Work");
	
	private Address address1 =
		new Address("123 A Street", "", "", "USA", "12345", "Massachusetts", "Boston", "Home");	
	private Address address2 =
		new Address("321 Z Avenue", "", "", "USA", "54321", "California", "Los Angeles", "Work");

	private EmailAddress email1 = new EmailAddress("example1@gmail.com", "home");
	private EmailAddress email2 = new EmailAddress("example1@EampleOneCompany.com", "work");
	

}
